﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.ComponentModel.Composition;
using System.Xml.Linq;
using System.IO;

namespace DynamicUIFramework
{
    [Export]
    [PartCreationPolicy(CreationPolicy.Shared)]
    public class RegionController
    {
        Dictionary<string, XElement> regions = new Dictionary<string, XElement>();

        public RegionController()
        {
            string[] files = Directory.GetFiles(UISetting.RegionPath, "*.xml", SearchOption.AllDirectories);
            foreach (var item in files)
            {
                XElement ele = XElement.Load(item);
                string name = ele.Attribute("name").Value;
                regions.Add(name, ele);
            }
        }

        public Dictionary<string, XElement> Regions
        { get { return regions; } }


        public XElement GetRegionElement(string name)
        {
            if (regions.ContainsKey(name))
                return regions[name];

            return null;
        }


        
    }
}
